home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / hack / 3_1_3 / src / quest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-07  |  7.2 KB  |  317 lines

  1. /*    SCCS Id: @(#)quest.c    3.1    93/03/10    */
  2. /*    Copyright 1991, M. Stephenson          */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. #include "hack.h"
  6.  
  7. #ifdef MULDGN
  8. /*  quest dungeon branch routines. */
  9.  
  10. #include "quest.h"
  11. #include "qtext.h"
  12.  
  13. #define Not_firsttime    (on_level(&u.uz0, &u.uz))
  14. #define Qstat(x)    (quest_status.x)
  15.  
  16. static void NDECL(on_start);
  17. static void NDECL(on_locate);
  18. static void NDECL(on_goal);
  19. static boolean NDECL(not_capable);
  20. static boolean NDECL(not_pure);
  21. static void FDECL(expulsion, (BOOLEAN_P));
  22. static void NDECL(chat_with_leader);
  23. static void NDECL(chat_with_nemesis);
  24. static void NDECL(chat_with_guardian);
  25.  
  26. static void
  27. on_start()
  28. {
  29.   if(!Qstat(first_start)) {
  30.     qt_pager(QT_FIRSTTIME);
  31.     Qstat(first_start) = TRUE;
  32.   } else if((u.uz0.dnum != u.uz.dnum) || (u.uz0.dlevel < u.uz.dlevel)) {
  33.     if(Qstat(not_ready) <= 2) qt_pager(QT_NEXTTIME);
  34.     else    qt_pager(QT_OTHERTIME);
  35.   }
  36. }
  37.  
  38. static void
  39. on_locate()
  40. {
  41.   if(!Qstat(first_locate)) {
  42.     qt_pager(QT_FIRSTLOCATE);
  43.     Qstat(first_locate) = TRUE;
  44.   } else if(u.uz0.dlevel < u.uz.dlevel)
  45.     qt_pager(QT_NEXTLOCATE);
  46. }
  47.  
  48. static void
  49. on_goal()
  50. {
  51.   if(!Qstat(made_goal)) {
  52.     qt_pager(QT_FIRSTGOAL);
  53.     Qstat(made_goal) = 1;
  54.   } else {
  55.     qt_pager(QT_NEXTGOAL);
  56.     if(Qstat(made_goal) < 7) Qstat(made_goal)++;
  57.   }
  58. }
  59.  
  60. void
  61. quest_init()
  62. {
  63. /*
  64.  *    Special setup modifications here:
  65.  *
  66.  *    Unfortunately, this is going to have to be done
  67.  *    on each newgame or restore, because you lose the permonst mods
  68.  *    across a save/restore :-)
  69.  *
  70.  *    1 - The Rogue Leader is the Tourist Nemesis.
  71.  *    2 - Priests start with a random alignment - convert the leader and
  72.  *        guardians here.
  73.  *    3 - Elves can have one of two different leaders, but can't work it
  74.  *        out here because it requires hacking the level file data (see
  75.  *        sp_lev.c).
  76.  */
  77. #ifdef TOURIST
  78.     if (pl_character[0] == 'T') {
  79.     mons[PM_MASTER_OF_THIEVES].msound = MS_NEMESIS;
  80.     mons[PM_MASTER_OF_THIEVES].mflags2 &= ~(M2_PEACEFUL);
  81.     mons[PM_MASTER_OF_THIEVES].mflags2 |= (M2_NASTY|M2_STALK|M2_HOSTILE);
  82.     mons[PM_MASTER_OF_THIEVES].mflags3 = M3_WANTSARTI | M3_WAITFORU;
  83.     } else
  84. #endif
  85.     if (pl_character[0] == 'P') {
  86.     mons[PM_ARCH_PRIEST].maligntyp = u.ualignbase[1]*3;
  87.     mons[PM_ACOLYTE].maligntyp = u.ualignbase[1]*3;
  88.     }
  89. }
  90.  
  91. void
  92. onquest()
  93. {
  94.     if(Not_firsttime)    return;
  95.     if(!Is_special(&u.uz)) return;
  96.  
  97.     if(Is_qstart(&u.uz)) on_start();
  98.     else if(Is_qlocate(&u.uz) && u.uz.dlevel > u.uz0.dlevel) on_locate();
  99.     else if(Is_nemesis(&u.uz)) on_goal();
  100.     return;
  101. }
  102.  
  103. void
  104. nemdead()
  105. {
  106.     if(!Qstat(killed_nemesis)) {
  107.         Qstat(killed_nemesis) = TRUE;
  108.         qt_pager(QT_KILLEDNEM);
  109.     }
  110. }
  111.  
  112. void
  113. artitouch()
  114. {
  115.     if(!Qstat(touched_artifact)) {
  116.         Qstat(touched_artifact) = TRUE;
  117.         qt_pager(QT_GOTIT);
  118.         exercise(A_WIS, TRUE);
  119.     }
  120. }
  121.  
  122. /* external hook for do.c (level change check) */
  123. boolean
  124. ok_to_quest()
  125. {
  126.     return((boolean)(Qstat(got_quest) || Qstat(got_thanks)));
  127. }
  128.  
  129. static boolean
  130. not_capable()
  131. {
  132.     return((boolean)(u.ulevel < MIN_QUEST_LEVEL));
  133. }
  134.  
  135. /* TODO:    This one needs tuning. */
  136. static boolean
  137. not_pure()
  138. {
  139. #ifdef WIZARD
  140.     if(wizard && (u.ualign.record < MIN_QUEST_ALIGN)) {
  141.  
  142.        You("are currently %d and require %d.",
  143.          u.ualign.record, MIN_QUEST_ALIGN);
  144.        if(yn_function("adjust?", NULL, 'y') == 'y')
  145.         u.ualign.record = MIN_QUEST_ALIGN;
  146.     }
  147. #endif
  148.   return((boolean)(u.ualign.record < MIN_QUEST_ALIGN));
  149. }
  150.  
  151. /*
  152.  * Expell the player to the stairs on the parent of the quest dungeon.
  153.  *
  154.  * This assumes that the hero is currently _in_ the quest dungeon and that
  155.  * there is a single branch to and from it.
  156.  */
  157. static void
  158. expulsion(seal)
  159. boolean seal;
  160. {
  161.   branch *br;
  162.   d_level *dest;
  163.  
  164.   br = dungeon_branch("The Quest");
  165.   dest = (br->end1.dnum == u.uz.dnum) ? &br->end2 : &br->end1;
  166.   assign_level(&u.utolev, dest);
  167.   u.utotype = 1; /* portal */
  168.   if (seal) {    /* remove the portal to the quest - sealing it off */
  169.     u.utotype |= 0200;
  170.     u.uevent.qexpelled = 1;
  171.   }
  172. }
  173.  
  174. static void
  175. chat_with_leader()
  176. {
  177. /*    Rule 0:    Cheater checks.                    */
  178.     if(u.uhave.questart && !Qstat(met_nemesis))
  179.         Qstat(cheater) = TRUE;
  180.  
  181. /*    It is possible for you to get the amulet without completing
  182.  *    the quest.  If so, try to induce the player to quest.
  183.  */
  184.     if(Qstat(got_thanks)) {
  185. /*    Rule 1:    You've gone back with/without the amulet.    */
  186.         if(u.uhave.amulet)    qt_pager(QT_HASAMULET);
  187.  
  188. /*    Rule 2:    You've gone back before going for the amulet.    */
  189.         else        qt_pager(QT_POSTHANKS);
  190.     }
  191.  
  192. /*    Rule 3: You've got the artifact and are back to return it. */
  193.       else if(u.uhave.questart) {
  194.         if(u.uhave.amulet)    qt_pager(QT_HASAMULET);
  195.         else        qt_pager(QT_OFFEREDIT);
  196.         Qstat(got_thanks) = TRUE;
  197.         u.uevent.qcompleted = 1;    /* you did it! */
  198.  
  199. /*    Rule 4: You haven't got the artifact yet.    */
  200.     } else if(Qstat(got_quest)) qt_pager(rn1(10, QT_ENCOURAGE));
  201.  
  202. /*    Rule 5: You aren't yet acceptable - or are you? */
  203.     else {
  204.       if(!Qstat(met_leader)) {
  205.         qt_pager(QT_FIRSTLEADER);
  206.         Qstat(met_leader) = TRUE;
  207.         Qstat(not_ready) = 0;
  208.       } else qt_pager(QT_NEXTLEADER);
  209.  
  210.       if(not_capable()) {
  211.         qt_pager(QT_BADLEVEL);
  212.         exercise(A_WIS, TRUE);
  213.         expulsion(FALSE);
  214.       } else if(not_pure()) {
  215.         qt_pager(QT_BADALIGN);
  216.         if(Qstat(not_ready) == MAX_QUEST_TRIES) {
  217.           qt_pager(QT_LASTLEADER);
  218.           expulsion(TRUE);
  219.         } else {
  220.           Qstat(not_ready)++;
  221.           exercise(A_WIS, TRUE);
  222.           expulsion(FALSE);
  223.         }
  224.       } else {    /* You are worthy! */
  225.         qt_pager(QT_ASSIGNQUEST);
  226.         exercise(A_WIS, TRUE);
  227.         Qstat(got_quest) = TRUE;
  228.       }
  229.     }
  230. }
  231.  
  232. void
  233. leader_speaks(mtmp)
  234.  
  235.     register struct monst *mtmp;
  236. {
  237.     /* maybe you attacked leader? */
  238.     if(!mtmp->mpeaceful) {
  239.         Qstat(pissed_off) = TRUE;
  240.         mtmp->data->mflags3 = 0;    /* end the inaction */
  241.     }
  242.  
  243.     if(Qstat(pissed_off)) {
  244.       qt_pager(QT_LASTLEADER);
  245.       expulsion(TRUE);
  246.     } else chat_with_leader();
  247.  
  248. }
  249.  
  250. static void
  251. chat_with_nemesis()
  252. {
  253. /*    The nemesis will do most of the talking, but... */
  254.         qt_pager(rn1(10, QT_DISCOURAGE));
  255.     if(!Qstat(met_nemesis)) Qstat(met_nemesis++);
  256. }
  257.  
  258. void
  259. nemesis_speaks()
  260. {
  261.     if(!Qstat(in_battle)) {
  262.       if(u.uhave.questart) qt_pager(QT_NEMWANTSIT);
  263.       else if(!Qstat(made_goal)) qt_pager(QT_FIRSTNEMESIS);
  264.       else if(Qstat(made_goal) < 3) qt_pager(QT_NEXTNEMESIS);
  265.       else if(Qstat(made_goal) < 7) qt_pager(QT_OTHERNEMESIS);
  266.       else if(!rn2(5))    qt_pager(rn1(10, QT_DISCOURAGE));
  267.       if(Qstat(made_goal) < 7) Qstat(made_goal)++;
  268.        Qstat(met_nemesis) = TRUE;
  269.     } else /* he will spit out random maledictions */
  270.       if(!rn2(5))    qt_pager(rn1(10, QT_DISCOURAGE));
  271. }
  272.  
  273. static void
  274. chat_with_guardian()
  275. {
  276. /*    These guys/gals really don't have much to say... */
  277.         qt_pager(rn1(5, QT_GUARDTALK));
  278. }
  279.  
  280. void
  281. quest_chat(mtmp)
  282.     register struct monst *mtmp;
  283. {
  284.  
  285.     switch(mtmp->data->msound) {
  286.         case MS_LEADER:    chat_with_leader(); break;
  287.         case MS_NEMESIS:    chat_with_nemesis(); break;
  288.         case MS_GUARDIAN:    chat_with_guardian(); break;
  289.         default:    impossible("quest_chat: Unknown quest character %s.",
  290.                    mon_nam(mtmp));
  291.     }
  292. }
  293.  
  294. void
  295. quest_talk(mtmp)
  296.     register struct monst *mtmp;
  297. {
  298.     switch(mtmp->data->msound) {
  299.         case MS_LEADER:    leader_speaks(mtmp); break;
  300.         case MS_NEMESIS:    nemesis_speaks(); break;
  301.         default:        break;
  302.     }
  303. }
  304.  
  305. void
  306. quest_stat_check(mtmp)
  307.     struct monst *mtmp;
  308. {
  309.     if(mtmp->data->msound == MS_NEMESIS)
  310.     Qstat(in_battle) = 
  311.         (mtmp->mcanmove && !mtmp->msleep && monnear(mtmp, u.ux, u.uy));
  312. }
  313.  
  314. #endif /* MULDGN */
  315.  
  316. /*quest.c*/
  317.